若要建立兩個汽車的實體,該如何建立?
  const carA = {
    wheels: 4,
    pressHorn() { console.log('AAA') },
  }
  const carB = {
    wheels: 4,
    pressHorn() { console.log('BBB') },
  }
  const Car = function (brand, sound = '888') {
    this.brand = brand
    this.wheels = 4
    this.pressHorn = function () { console.log(sound) }
  }
  const carA = new Car('AAA')
  const carB = new Car('BBB', 'BBB')
  Car.prototype.pressHorn = function () {
    console.log(`${this.brand} ${this.sound}`)
  }
  // true 表 Function 來自同一個記憶體位置
  console.log(carA).pressHorn() === carB.pressHorn())
  const Car = function (brand,sound) {
    this.brand = brand
    this.wheel = 4
    this.pressHorn = function (){ console.log(sound) }
    return {
      brand,
      pressHorn: this.pressHorn
    }
  }
  const test = new Car('A','AAA')
  console.log(test.wheels) // undefined 不可取得
  console.log(test.brand) // 可取得
  class Car {
    // 寫於 constructor的內容,皆會在記憶體創一份新的
    // 因此 方法避免寫於 constructor 內部
    constructor(brand = 'default') {
      // constructor內容會於實體建立時執行
      this.brand = brand
      this.init() 
    }
    init() { console.log('init') }
    pressHorn(){
      console.log(`${this.brand} ${this.sound}`)
    }
  }
  class Calculator {
    constructor(str) { this.str = str }
    static add(a, b) { console.log(a + b) }
    hey() { return this.str }
  }
  const calculatorA = new Calculator('hey')
  // 建立實體後,無法透過實體使用該函式
  console.log(calculatorA.add) // undefined
  console.log(calculatorA.hey()) // 'hey'
  // 沒有建立實體即可使用
  Calculator.add(1, 4) // 3
  class Option {
    constructor(key, value) {
      if (typeof key !== 'undefined') { this[`_${key}`] = value }
    }
    get color() {
      if (this._color !== undefined) { return this._color } 
      return 'no color prop'
    }
    set color(value) { this._color = value }
  }
  const op1 = new Option('color', 'red')
  op1.color = 'yellow'
  const op2 = new Option('action', 'run')
  op2.color = 'yellow'
  Object.defineProperty(obj, 'key', {
    get() {
      // 取得值前 可於此作format....etc
      return this.name
    },
    set(val) {
      // 設定值前可以作一些 例外判斷 (falsy...etc)
      this.name = val
      console.log(val)
    },
  })
  const User = function ({ name = 'default', age }) {
    this.name = name // 可預設但可傳入修改
    this.age = age
    this.gender = 'male' // 可預設不給用傳入的
  }
  // 傳入順序無差,以 Key為基準
  let test = new User({ age: 30 })
  console.log(test.name, test.gender) // 'default' 'male'
// ESLint/MDN 不建議使用 __proto__ 取得原型
const CarProto = Car.__proto__
// 推薦使用 ES5
const CarProto = Object.getPrototypeOf(Car)
  // 判斷 'str' 是否在 String 之下
  console.log('str' instanceof String) 
  // false,因為此種表示方法為原始型別,其原型鏈為 undefined
  // 使用 new 關鍵字建立物件
  const newStr = new String('newStr')
  console.log(newStr instanceof String )
  console.log(newStr instanceof Object )
  // 皆true,String & Object 皆於 newStr 原型鏈上
  // Object.literal
  const obj = { test(){ console.log('hi') } }
  const mark = new Person()
  const str =  new String()